-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support Chart.transform_filter(*predicates, **constraints)
#3664
Open
dangotbanned
wants to merge
23
commits into
main
Choose a base branch
from
transform-filter-predicates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+174
−45
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Includes deprecation handling
- Need to widen the definition of `_PredicateType` - To support this, we'll need to model with `TypedDict`(s)
dangotbanned
commented
Oct 30, 2024
tests/examples_arguments_syntax/line_chart_with_cumsum_faceted.py
Outdated
Show resolved
Hide resolved
This alias may be redundant now, need to review that later
Didn't account for a `TypeError` that can be triggered if `more_predicates` isn't composable. E.g `filter={"field": "year", "oneOf": [1955, 2000]}`
dangotbanned
changed the title
feat(DRAFT): Support
feat: Support Oct 31, 2024
Chart.transform_filter(*predicates, **constraints)
Chart.transform_filter(*predicates, **constraints)
This was referenced Oct 31, 2024
Makes use of #3668 Resolves #3664 (comment)
- Builds on the style introdcued for `alt.when` - Shows a few specific kinds of predicates - due to the prior doc listing 5 #3657
Need to forgo all type safety here, since it would permit `_PredicateType` instead of the narrower `_FieldEqualType`
I added this while trying to resolve a different typing issue, purely to see what was inferred
Think this makes it clearer how each of these align
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Will close #3657
Description
This PR enables the same syntax from
alt.when
to be used inalt.TopLevelMixin.transform_filter
.Honestly, I'm still a bit shocked by how little needed changing in the implementation.
Besides tweaking the signature and handling the deprecated argument, it really was just these 2 lines:
altair/altair/vegalite/v5/api.py
Lines 3102 to 3103 in 2d57d6e
To explain this,
_parse_when
returns our version of VL-Condition.We can either use that as-is or unwrap the
"test"
key, which stores an already parsed test VL-Predicate.Besides this small change, most of the PR consists of new docs & tests.
Doc (Examples)
Setting up a common chart:
Singular predicates can be expressed via
datum
:We can also use selection parameters directly:
Or a field predicate:
Predicates can be composed together using logical operands:
Predicates passed as positional arguments will be reduced with
&
:Using keyword-argument
constraints
can simplify compositions like:Tasks
filter
as a keyword argument.transform_filter()
implementation(*predicates, **constraints)
syntax (b497039)dict
typing issue.transform_filter()
docstring (7a0cc42)